package com.sl.biz.modular.process.dao.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.process.dao.domain.dto.ProcessCompObjectDTO;
import com.sl.biz.modular.process.dao.domain.entity.ProcessCompObjectDO;
import com.sl.biz.modular.process.dao.mapper.ProcessCompObjectMapper;
import com.sl.biz.modular.process.dao.service.ProcessCompObjectDaoService;
import com.sl.common.enums.CommonDeleteFlagEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ProcessCompObjectDaoServiceImpl extends ServiceImpl<ProcessCompObjectMapper, ProcessCompObjectDO> implements ProcessCompObjectDaoService {
    @InterceptorIgnore(tenantLine = "true")
    @Override
    public List<ProcessCompObjectDTO> queryByCodesAndVersions(List<String> compCodeList, List<String> versionList, List<String> orgList) {
        LambdaQueryWrapper<ProcessCompObjectDO> wrapper = Wrappers.lambdaQuery();
//        wrapper.eq(ProcessCompObjectDO::getDeleted, DataBaseConstant.DELETE_VALID);
        wrapper.in(ProcessCompObjectDO::getCompCode, compCodeList);
        wrapper.in(ProcessCompObjectDO::getCompVersion, versionList);
        wrapper.in(ProcessCompObjectDO::getOrgId, orgList);
        List<ProcessCompObjectDO> list = baseMapper.selectList(wrapper);
        return BeanUtil.copyToList(list, ProcessCompObjectDTO.class);
    }

    @InterceptorIgnore(tenantLine = "true")
    @Override
    public ProcessCompObjectDTO queryByCodeAndVersion(String orgId, String compCode, String version) {
        LambdaQueryWrapper<ProcessCompObjectDO> wrapper = Wrappers.lambdaQuery();
//        wrapper.eq(ProcessCompObjectDO::getDeleted, DataBaseConstant.DELETE_VALID);
        wrapper.eq(ProcessCompObjectDO::getCompCode, compCode);
        wrapper.eq(ProcessCompObjectDO::getCompVersion, version);
        wrapper.eq(StrUtil.isNotBlank(orgId), ProcessCompObjectDO::getOrgId, orgId);
        ProcessCompObjectDO list = baseMapper.selectOne(wrapper);
        return BeanUtil.copyProperties(list, ProcessCompObjectDTO.class);
    }

    @Override
    public ProcessCompObjectDTO queryByCodeAndVersion(String compCode, String version) {
        LambdaQueryWrapper<ProcessCompObjectDO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ProcessCompObjectDO::getCompCode, compCode);
        wrapper.eq(ProcessCompObjectDO::getCompVersion, version);
        ProcessCompObjectDO list = baseMapper.selectOne(wrapper);
        return BeanUtil.copyProperties(list, ProcessCompObjectDTO.class);
    }

    @Override
    public Boolean removeByCompCodeAndVersion(String compCode, String compVersion) {
        LambdaUpdateWrapper<ProcessCompObjectDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(ProcessCompObjectDO::getCompCode, compCode);
        lambdaUpdateWrapper.eq(ProcessCompObjectDO::getCompVersion, compVersion);
        return super.remove(lambdaUpdateWrapper);
    }
}
